package com.elitetyc.customview.custom;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.elitetyc.customview.R;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by elitetyc on 2019/6/11.
 * Describe:
 */
public class OneButtonDialog extends Dialog {
    private CircleImageView iv_dialog_type;
    private TextView tv_message,tv_btn;

    public OneButtonDialog(Context context, DialogEnum type, String message, String btnText) {
        super(context,R.style.MyDialog);
        setContentView(R.layout.dialog_one_button);

        iv_dialog_type = findViewById(R.id.iv_dialog_type);
        tv_message = findViewById(R.id.tv_message);
        tv_btn = findViewById(R.id.tv_btn);

//        根据类型显示不同的图标
        switch (type){
            case DIALOG_OK:
                break;
            case DIALOG_TIMEING:
                break;
            case DIALOG_ERROR:
                break;
            case DIALOG_WRNING:
                break;
            default:
                break;
        }
        tv_message.setText(message);
        tv_btn.setText(btnText);

        Window dialogWindow = getWindow();
        Activity activity = (Activity) context;
        WindowManager m = activity.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.75); // 宽度设置为屏幕的0.95
        dialogWindow.setAttributes(p);
//        点击屏幕外不消失，点击返回键消失
        setCanceledOnTouchOutside(false);
    }

    public void onButtonClick(View.OnClickListener onClickListener){
        tv_btn.setOnClickListener(onClickListener);
    }
}
